2020-2021 Sunseeker Telemetry and Lighting System
eusci_b_i2c_ex3_slaveRxMultiple.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //******************************************************************************
35 // EUSCI_B0 I2C Slave RX single bytes from MSP430 Master
36 //
37 // Description: This demo connects two MSP430's via the I2C bus. The master
38 // transmits to the slave. This is the slave code. The interrupt driven
39 // data receiption is demonstrated using the USCI_B0 RX interrupt.
40 //
41 // Tested on MSP430F67791A
42 //
43 // /|\ /|\
44 // 10k 10k
45 // slave | | master
46 // ----------------- | | -----------------
47 // -|XIN P2.6/UCB0SDA|<-|----+->|P2.6/UCB0SDA XIN|-
48 // | | | | |
49 // -|XOUT | | | XOUT|-
50 // | P2.5/UCB0SCL|<-+------>|P2.5/UCB0SCL |
51 // | | | |
52 // | | | |
53 //
54 
55 //******************************************************************************
56 //*****************************************************************************
57 //
58 //Set the address for slave module. This is a 7-bit address sent in the
59 //following format:
60 //[A6:A5:A4:A3:A2:A1:A0:RS]
61 //
62 //A zero in the "RS" position of the first byte means that the master
63 //transmits (sends) data to the selected slave, and a one in this position
64 //means that the master receives data from the slave.
65 //
66 //*****************************************************************************
67 #define SLAVE_ADDRESS 0x48
68 
69 uint8_t RXData;
70 
71 void main(void)
72 {
73  WDT_A_hold(WDT_A_BASE);
74 
75  //Configure Pins for I2C (UCB0SCL, UCB0SDA)
76  //Set P2.5 and P2.6 as Module Function Input
77  GPIO_setAsPeripheralModuleFunctionInputPin(
78  GPIO_PORT_P2,
79  GPIO_PIN5 + GPIO_PIN6
80  );
81 
82  // eUSCI configuration
83  EUSCI_B_I2C_initSlaveParam param = {0};
84  param.slaveAddress = SLAVE_ADDRESS;
85  param.slaveAddressOffset = EUSCI_B_I2C_OWN_ADDRESS_OFFSET0;
86  param.slaveOwnAddressEnable = EUSCI_B_I2C_OWN_ADDRESS_ENABLE;
87  EUSCI_B_I2C_initSlave(EUSCI_B0_BASE, &param);
88 
89  EUSCI_B_I2C_enable(EUSCI_B0_BASE);
90 
91  EUSCI_B_I2C_clearInterrupt(EUSCI_B0_BASE,
92  EUSCI_B_I2C_RECEIVE_INTERRUPT0
93  );
94 
95  EUSCI_B_I2C_enableInterrupt(EUSCI_B0_BASE,
96  EUSCI_B_I2C_RECEIVE_INTERRUPT0
97  );
98 
99  __bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts
100  __no_operation();
101 }
102 
103 //------------------------------------------------------------------------------
104 // The USCI_B0 data ISR RX vector is used to move received data from the I2C
105 // master to the MSP430 memory.
106 //------------------------------------------------------------------------------
107 //------------------------------------------------------------------------------
108 // The USCI_B0 state ISR TX vector is used to wake up the CPU from LPM0 in order
109 // to process the received data in the main program. LPM0 is only exit in case
110 // of a (re-)start or stop condition when actual data was received.
111 //------------------------------------------------------------------------------
112 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
113 #pragma vector=USCI_B0_VECTOR
114 __interrupt
115 #elif defined(__GNUC__)
116 __attribute__((interrupt(USCI_B0_VECTOR)))
117 #endif
118 void USCIB0_ISR(void)
119 {
120  switch(__even_in_range(UCB0IV, USCI_I2C_UCBIT9IFG))
121  {
122  case USCI_NONE: // No interrupts break;
123  break;
124  case USCI_I2C_UCALIFG: // Arbitration lost
125  break;
126  case USCI_I2C_UCNACKIFG: // NAK received (master only)
127  break;
128  case USCI_I2C_UCSTTIFG: // START condition detected with own address (slave mode only)
129  break;
130  case USCI_I2C_UCSTPIFG: // STOP condition detected (master & slave mode)
131  break;
132  case USCI_I2C_UCRXIFG3: // RXIFG3
133  break;
134  case USCI_I2C_UCTXIFG3: // TXIFG3
135  break;
136  case USCI_I2C_UCRXIFG2: // RXIFG2
137  break;
138  case USCI_I2C_UCTXIFG2: // TXIFG2
139  break;
140  case USCI_I2C_UCRXIFG1: // RXIFG1
141  break;
142  case USCI_I2C_UCTXIFG1: // TXIFG1
143  break;
144  case USCI_I2C_UCRXIFG0: // RXIFG0
145  RXData = EUSCI_B_I2C_slaveGetData(EUSCI_B0_BASE);
146  break;
147  case USCI_I2C_UCTXIFG0: // TXIFG0
148  break;
149  case USCI_I2C_UCBCNTIFG: // Byte count limit reached (UCBxTBCNT)
150  break;
151  case USCI_I2C_UCCLTOIFG: // Clock low timeout - clock held low too long
152  break;
153  case USCI_I2C_UCBIT9IFG: // Generated on 9th bit of a transmit (for debugging)
154  break;
155  default:
156  break;
157  }
158 }
159 
void USCIB0_ISR(void)
void main(void)
#define SLAVE_ADDRESS
MPU_initThreeSegmentsParam param
__no_operation()